package zakladki.AS3 {
import AS3.constants.combo.FlightClass;

import mx.core.FlexGlobals;

public class PublicTransportChangeListener {

    private var mainApplication:Fossilminator = FlexGlobals.topLevelApplication as Fossilminator;

    private var imgComponents:PublicTransportImageManager;
    private var controls:PublicTransportControls;

    public function PublicTransportChangeListener(imgComponents:PublicTransportImageManager, controls:PublicTransportControls) {
        this.imgComponents = imgComponents;
        this.controls = controls;
    }

    public function cityBusChanged(calc:Boolean):void {
        var value:String = new String(controls.cityBusSelector.value);
        var display:Boolean = controls.cityBusSelector.value != 0;

        imgComponents.cityBusChanged(value,display);

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    public function longDistanceBusChanged(calc:Boolean):void {
        var value:String = new String(controls.longDistanceBusSelector.value);
        var display:Boolean = controls.longDistanceBusSelector.value != 0;

        imgComponents.longDistanceBusChanged(value,display);

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    public function miniBusChanged(calc:Boolean):void {
        var value:String = new String(controls.miniBusSelector.value);
        var display:Boolean = controls.miniBusSelector.value != 0;

        imgComponents.miniBusChanged(value,display);

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    public function tramSubwayChanged(calc:Boolean):void {
        var value:String = new String(controls.tramSubwaySelector.value);
        var display:Boolean = controls.tramSubwaySelector.value != 0;

        imgComponents.tramSubwayChanged(value,display);

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    public function suburbanTrainChanged(calc:Boolean):void {
        var value:String = new String(controls.suburbanTrainSelector.value);
        var display:Boolean = controls.suburbanTrainSelector.value != 0;

        imgComponents.suburbanTrainChanged(value,display);

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    public function longDistanceTrainChanged(calc:Boolean):void {
        var value:String = new String(controls.longDistanceTrainSelector.value);
        var display:Boolean = controls.longDistanceTrainSelector.value != 0;

        imgComponents.longDistanceTrainChanged(value,display);

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    public function taxiChanged(calc:Boolean):void {
        var value:String = new String(controls.taxiSelector.value);
        var display:Boolean = controls.taxiSelector.value != 0;

        imgComponents.taxiChanged(value,display);

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    public function flightClassChanged(calc:Boolean):void {
        var flightClass:int = controls.flightClassCombo.selectedItem.data;

        if (flightClass == FlightClass.ECONOMY) {
            imgComponents.transPublic.klasa.gotoAndStop(3);
        }
        else if (flightClass == FlightClass.BUSINESS) {
            imgComponents.transPublic.klasa.gotoAndStop(2);
        }
        else if (flightClass == FlightClass.FIRST) {
            imgComponents.transPublic.klasa.gotoAndStop(1);
        }

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    public function shortDistanceFlightChanged(calc:Boolean):void {
        var value:String = new String(controls.shortDistanceFlightsSelector.value);
        var display:Boolean = controls.shortDistanceFlightsSelector.value != 0;

        imgComponents.shortDistanceFlightChanged(value,display);

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    public function longDistanceFlightChanged(calc:Boolean):void {
        var value:String = new String(controls.longDistanceFlightsSelector.value);
        var display:Boolean = controls.longDistanceFlightsSelector.value != 0;

        imgComponents.longDistanceFlightChanged(value,display);

        if (calc) {
            updatePerson(createSelectedData());
            mainApplication.calculate();
        }
    }

    private function createSelectedData():PublicTransportSelectedData {
        return new PublicTransportSelectedData(controls);
    }

    private function updatePerson(selectedData:PublicTransportSelectedData):void {
        mainApplication.publicTransportUpdate(selectedData);

    }
}
}

